﻿// News Framework
// (C) Tanzim Saqib. Oct 25, 2010.
// http://TanzimSaqib.com | http://newsfx.codeplex.com

namespace TanzimSaqib.NewsFramework
{
    using System;
    using System.IO;
    using System.Windows;
    using System.Xml.Linq;
    using System.Collections.Generic;

    public sealed class Feeds : Dictionary<string, FeedInfo>
    {
        public string Main { get; set; }

        internal Feeds(string namespaceMainPage, string feedPath)
        {
            var streamInfo = Application.GetResourceStream(new Uri( FxConstants.DifferentAssemblyPath.FormatWith(namespaceMainPage, feedPath), UriKind.Relative));

            using (var reader = new StreamReader(streamInfo.Stream))
            {
                var settings = XElement.Load(reader);

                Main = settings.Attribute("main").Value;

                foreach (var setting in settings.Elements())
                {
                    Add(setting.Attribute("title").Value, new FeedInfo(setting.Attribute("title").Value, setting.Attribute("subtitle").Value, setting.Attribute("url").Value));
                }
            } 
        }
    }
}
